<script src="../media/system/js/mootools-core.js" type="text/javascript"></script>
<script src="../media/system/js/core.js" type="text/javascript"></script>
<?php
    $aut = new bgAuthorize();
 ?>
<form action="index.php?option=com_info_leader" method="post" name="adminForm" id="adminForm" class="adminform">
<?php
    //check user group
   $group=$aut->getUserGroup();
   $u=JFactory::getUser();
   $u_ocba= $u->USEM_OCBA_CODE;
   if($group!=11)
   {
?>
	<fieldset id="filter-bar">
            <div style="border: solid 1px #ccc; padding: 10px;border-radius: 5px;">
            <table border=0 class="coach-search" style="width: 100%;margin:auto;">
            
               <tr>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;width:15%;">センター・クラブ種別</td>
                <td style="width: 13%;">
                   
                    <select class="inputbox medium" id="center" name="center">
                           <option value="0" <?php if ($this->list['center'] == 0) { echo ' selected="selected"';} ?> >指定しない</option>
                           <option value="1"<?php if ($this->list['center'] == 1) { echo ' selected="selected"';} ?>>センター</option>
                           <option value="2" <?php if ($this->list['center'] == 2) { echo ' selected="selected"';} ?>>クラブ</option>
                </select>
                </td>
                <td style="width: 13%;"></td>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;width:13%;">研修回</td>
                <td style="width: 25%"><input type="text" class="inputbox smallx" name="term" id="term" value="<?php echo $this->list['term'] ?>" />
                
                    <select class="inputbox small" name="unit" id="unit">
                       <option value="0" selected="selected">指定しない</option>
                       <option value="1" <?php if ($this->list['unit'] == 1) { echo ' selected="selected"';} ?>>回</option>
                       <option value="2" <?php if ($this->list['unit'] == 2) { echo ' selected="selected"';} ?>>期</option>
                       <option value="3" <?php if ($this->list['unit'] == 3) { echo ' selected="selected"';} ?>>年度</option>
                       
                    </select>
                </td>
               </tr>
               <tr>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;">地区</td>
                <td>
                    <select class="inputbox medium" id="area" name="area">
                        <option value="0" selected="selected">指定しない</option>
                        <?php
                            foreach($this->area as $value){
                          ?>
                          <option value="<?php echo $value->AREA_CODE; ?>"<?php if ($this->list['area'] == $value->AREA_CODE) { echo ' selected="selected"';} ?>>
                          <?php echo $value->AREA_NAME; ?></option>
                          <?php
                            }
                          ?>
                    </select>
                </td>
                <td></td>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;">指導者名</td>
                <td colspan="5"><input type="text" class="inputbox medium" id="nameld" name="nameld" value="<?php echo $this->list['nameld']?>"/></td>
                <!--
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;">人材バンク</td>
                <td colspan="2"><input type="text" class="inputbox medium" id="human_rs" name="human_rs" value="<?php echo $this->list['human_rs'] ?>"/></td>
                -->
               </tr>
               <tr>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;">都道府県</td>
                <td>
                <span id="area_pref">
                    <select class="inputbox medium" id="pref" name="pref">
                     <option value="0" selected="selected">指定しない</option>    
                          <?php
                            foreach($this->pref as $value){
                          ?>
                          <option value="<?php echo $value->PREF_CODE; ?>"<?php if ($this->list['pref'] == $value->PREF_CODE ) { echo ' selected="selected"';} ?>>
                          <?php echo $value->PREF_NAME; ?></option>
                          <?php
                            }
                          ?>
                    </select>
                </span>
                </td>
                <td></td>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;">免許期日</td>
                <td colspan="2">
                    <select class="inputbox medium" id="ls_date" name="ls_date">
                        <option value="0" <?php if ($this->list['ls_date'] == 0) { echo ' selected="selected"';} ?>>指定しない</option>
                        <option value="1" <?php if ($this->list['ls_date'] == 1) { echo ' selected="selected"';} ?>>有効期限内</option>
                        <option value="2" <?php if ($this->list['ls_date'] == 2) { echo ' selected="selected"';} ?>>有効期限切れ</option>
                    </select>
                </td>
                  
               </tr>
               <tr>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;">センター・クラブ名</td>
                <td><input type="text" class="inputbox medium" id="namecc" name="namecc" value="<?php echo $this->list['namecc'] ?>" /></td>
                <td></td>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;">指導者会</td>
                <td colspan="2"><input type="text" class="inputbox medium" id="ld_meeting" name="ld_meeting"  value="<?php echo $this->list['ld_meeting'] ?>" /></td>
                
               </tr>
               <tr>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;">指導者種別</td>
                
                    <?php
                        $i = 0;
                        $this->cocm = $this->cocm ? $this->cocm : array();
                        foreach($this->cocm as $key=>$value){
                            $i++;
                    ?>
                    <td>
                    <input type="checkbox" name="chb<?php echo $value->COCM_CODE; ?>" id="chb<?php echo $value->COCM_CODE; ?>" value="<?php echo $value->COCM_CODE; ?>" <?php if(isset($this->list['chb'.$value->COCM_CODE])){ echo 'checked="checked"'; } ?>  /><label for="chb<?php echo $value->COCM_CODE; ?>"><?php echo $value->COCM_NAME; ?></label>
                    </td>
                    <?php
                            if($i==4){
                                $i = 0;
                                echo "</tr><tr><td>"; 
                            }    
                        }
                    ?>
                
               </tr>
               <tr>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;">事業協力</td>
                <?php
                        $i = 0;
                        foreach($this->lkdt as $key=>$value){
                            $i++;
                    ?>
                    <td>
                    <input type="checkbox" name="chll<?php echo $value->LKDT_CODE; ?>" id="chll<?php echo $value->LKDT_CODE; ?>" value="<?php echo $value->LKDT_NAME; ?>" <?php if(isset($this->list['chll'.$value->LKDT_CODE])){ echo 'checked="checked"'; } ?>  /><label for="chll<?php echo $value->LKDT_CODE; ?>"><?php echo $value->LKDT_NAME; ?></label>
                    </td>
                    <?php
                            if($i==4){
                                $i = 0;
                                echo "</tr><tr><td>"; 
                            }    
                        }
                    ?>
               <tr>
               <tr>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;">人材バンク</td>
                
                    <?php
                        $i = 0;
                        foreach($this->human as $key=>$value){
                            $i++;
                    ?>
                    <td>
                    <input type="checkbox" name="chhh<?php echo $value->HUMAN_CODE; ?>" id="chhh<?php echo $value->HUMAN_CODE; ?>" value="<?php echo $value->HUMAN_CODE; ?>" <?php if(isset($this->list['chhh'.$value->HUMAN_CODE])){ echo 'checked="checked"'; } ?>  /><label for="chhh<?php echo $value->HUMAN_CODE; ?>"><?php echo $value->HUMAN_NAME; ?></label>
                    </td>
                    <?php
                            if($i==4){
                                $i = 0;
                                echo "</tr><tr><td>"; 
                            }    
                        }
                    ?>
                
               </tr>
                <td></td>
                <td colspan="5" style="padding-left: 30%;">
                    <button type="submit" class="btn">検索</button>
                    <button type="button" onclick="document.id('center').value='0';document.id('unit').value='0';document.id('term').value='';
                        document.id('area').value='0';document.id('pref').value='0';document.id('namecc').value='';document.id('nameld').value='';
                        document.id('ld_meeting').value='';document.id('ls_date').value='0';
                        <?php
                            foreach($this->cocm as $key=>$value){
                                
                        ?>
                            document.id('chb<?php echo $value->COCM_CODE; ?>').checked = false;
                        <?php } ?>
                        
                        <?php
                            $model = $this->getModel();
                            $a=$model->getTotalLkdt();
                            for($i=1;$i<=$a;$i++)
                            {
                                $this->list['chll'.$i] = &JRequest::getVar('chll'.$i);
                            ?>
                            document.id('chll<?php echo $i; ?>').checked = false;
                        <?php } ?>
                        
                        <?php
                            $model = $this->getModel();
                            $b=$model->getTotalHuman();
                            for($i=1;$i<=$b;$i++)
                            {
                                $this->list['chhh'.$i] = &JRequest::getVar('chhh'.$i);
                            ?>
                            document.id('chhh<?php echo $i; ?>').checked = false;
                        <?php } ?>

                       
                        this.form.submit();">クリア</button></td>
               </tr>
               
            </table>
			</div>
		
	</fieldset>
    <?php } ?>
    
    <div  webmemes_parsed="1">  
        <!--<button class="float-left button" ><a style="text-decoration: none;" href="index.php?option=com_certification">資格作成・編集</a></button>-->
        <?php $arr = $aut->getPerm($aut->getUserGroup(),'com_certification');
            if($arr->PRRM_INSERT || $arr->PRRM_UPDATE || $arr->PRRM_DELETE || $arr->PRRM_EDITOWN){
        ?>
            <button class="float-left button" href="index.php?option=com_certification" >資格作成・編集</button> 
        <?php } ?>
			<div webmemes_parsed="1">
				<div class="toolbar-list" id="toolbar" webmemes_parsed="1">
                                    
                        <ul>
                        <?php if($aut->checkAdd()){ ?>
                        <li class="button" id="toolbar-new">
                        <a href="#" onclick="Joomla.submitbutton('add')" class="toolbar">
                        <span class="icon-32-new" webmemes_parsed="1">
                        </span>
                        作成
                        </a>
                        </li>
                        <?php
                         }
                        if($aut->checkEdit() || $att->checkEditOwn()){
                        ?>
                        <li class="button" id="toolbar-edit">
                        <a href="#" onclick="if (document.adminForm.boxchecked.value==0){alert('編集対象のものを指定してから行ってください。');}else{ Joomla.submitbutton('edit')}" class="toolbar">
                        <span class="icon-32-edit" webmemes_parsed="1">
                        </span>
                        編集
                        </a>
                        </li>
                        <?php
                        }
                        if($aut->checkDelete()){
                        ?>
                        <li class="button" id="toolbar-delete">
                        <a href="#" onclick="if (document.adminForm.boxchecked.value==0){alert('編集対象のものを指定してから行ってください。');}else{ Joomla.submitbutton('remove')}" class="toolbar">
                        <span class="icon-32-delete" webmemes_parsed="1">
                        </span>
                        削除
                        </a>
                        </li>
                        <?php
                        }
                        if($aut->getUserGroup() == '8' || $aut->getUserGroup() == '9'){
                        
                        ?>
                        <li class="button" id="toolbar-csv">
                        <a href="#" onclick="Joomla.submitbutton('export_csv')" class="toolbar">
                        <span class="icon-32-csv" webmemes_parsed="1">
                        </span>
                        CSV出力
                        </a>
                        </li>
                        <?php } ?>
                        </ul>
                        
                </div>
                        					
			</div>
	</div>
    <div class="clr"> </div>

	<table class="adminlist">
		<thead>
			<tr>
				<th width="2%" class="center">
                      <input type="checkbox" name="checkall-toggle" value="" title="Check All" onclick="Joomla.checkAll(this)"/>
				</th>
                <th width="12%">
					<label class="labelth">指導者システムコード</label>			
                </th>
				<th width="15%">
					<label class="labelth">指導員コード</label>			
                </th>
                
				<th width="15%">
					<label class="labelth">氏名</label>			
                </th>
				<th width="20%">
					<label class="labelth">所属</label>			
                </th>
				<th width="4%">
					<label class="labelth">常勤</label>			
                </th>
				<th width="15%">
					<label class="labelth">指導員種別</label>
                </th>
				<th width="10%">
					<label class="labelth">免許期日</label>
                </th>
                <th width="10%">
					<label class="labelth">公開済/一時保存中</label>
                </th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="15">
				    <?php echo $this->pagination->getListFooter(); ?>	
                </td>
            </tr>
		</tfoot>
		<tbody>
            <?php 
            $rows = $this->rows;
            if($rows != null){
                foreach($rows as $k=>$row){
                
            ?> 
		  <tr class="row<?php echo $k%2?>">
            <td class="center">
			<input type="checkbox" id="cb<?php echo $row->COCH_CODE ?>" name="cid[]" value="<?php echo $row->COCH_CODE ?>" onclick="Joomla.isChecked(this.checked);"/>
            </td>
			
            <td class="center"><a href="#" onclick="document.id('cb<?php echo $row->COCH_CODE ?>').checked=true;Joomla.submitbutton('edit');"><?php echo $row->COCH_CODE; ?></a></td>
			<td class="center"><?php echo $row->COCH_CD; ?></td>
            <td><?php echo $row->COCH_NAME; ?></td>
			<td><?php echo $row->OCBA_NAME; ?></td>
            <td class="center"><?php if(($row->COCH_WOKF==1)) echo "<font size='2' face='ＭＳ Ｐゴシック, Osaka' class='font03'>●</font>";  ?></td>
            <td >
                <?php 
                    $a=$row->COCH_CODE;
                    //$colis = $this->colis;
                    $model=$this->getModel();
                    $where="";
                    $this->colis =$model->loadcoli($a);
                    if($this->colis != null){
                        foreach($this->colis as $k=>$coli){ 
                           $where=$where.$coli->COCM_NAME;
                           $where=$where.',';
                        }
                    }
                    echo substr($where,0,-1);
                ?> 
            </td>
            
            <td class="center">            
                <?php 
                    // $a=$row->COCH_CODE;
                    // //$colis = $this->colis;
                    // $model=$this->getModel();
                    // $where="";
                    // $this->colis =$model->loadcoli($a);
                    // if($this->colis != null){
                    //     foreach($this->colis as $k=>$coli){ 
                    //         if($coli->COLI_JDATE!="0000-00-00 00:00:00")
                    //         {
                    //             $where=$where.HelperBG::F_GetDate_JP($coli->COLI_JDATE);
                    //             $where=$where.',';
                    //         }
                           
                    //     }
                    // }
                    // echo substr($where,0,-1);
                    if($row->COCH_LDATE != "0000-00-00 00:00:00" && $row->COCH_LDATE != null)
                        echo HelperBG::F_GetDate_JP($row->COCH_LDATE);
                ?> 
            </td>
            <td class="center">
                <?php if ($row->COCH_FLAG == 1) {echo '公開済'; } else echo '一時保存中'; ?>
            </td>
		  </tr>
          <?php
                }
            }else{
            ?>
                <tr>
                    <td class="center" colspan="9">データは見つかりませんでした</td>
                </tr>
            <?php    
            }
             ?>
          
		</tbody>
	</table>
    <!-- <input type="submit" value="同期" style="width: 75px;float:right;"/> -->
	<div>
		<input type="hidden" name="task" value=""/>
		<input type="hidden" name="boxchecked" value="0"/>
    </div>
</form>

<script>
Joomla.submitbutton = function(task){
    if(task == 'remove'){
        if(!confirm('選択したデータを削除します。よろしいですか？')){
            return false;
        }
    }
       
       Joomla.submitform(task, document.getElementById('adminForm'));
       
 }
 
 jq(document).ready(function(){       
		jq("#area").change(function(){
		  
			var id = document.getElementById("area").value;
			var url = "index.php?option=com_info_leader&task=selectArea&area_code="+id;
            
            jq.get(url, function(data) {
              jq('#area_pref').html(data);
            });
            	
		})
 	});
</script>